﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Model;
using MsDAL;
using System.ComponentModel;
using Components;

namespace ServiceHelper
{
    [DataObjectAttribute]
    public partial class Ord9a00Manager : Ord9a00Base
    {
        private static Ord9a00Manager _entity;

        public static Ord9a00Manager Entity
        {
            get
            {
                if (_entity == null)
                    _entity = new Ord9a00Manager();
                return _entity;
            }
        }

        #region 个人代码
        public string SaveData(Hashtable tb, DataTable dtl, DataTable deldata, string action, string usercode)
        {
            List<SqlApp> lst = new List<SqlApp>();

            Ord9a00 model = null;
            if ("A" == action && (dtl == null || dtl.Rows.Count == 0)) return "明细中没有数据，不需要保存！";

            string appstr = Context.GetAppByUserCode(usercode);

            if ("A" == action) //新增
            {
                DateTime now = DateTime.Now;
                string seller = Validation.ToString(tb["seller"]); //销售者
                string sellid = Validation.ToString(tb["sellid"]); //销售商
                string shopid = Validation.ToString(tb["shopid"]); //门店
                DateTime sellertime = Convert.ToDateTime(tb["sellertime"]);

                foreach (DataRow dr in dtl.Rows)
                {
                    model = new Ord9a00();
                    Components.CommonUtil.GetInstance.CopyProperties(model, dr);
                    model.Listid = Components.Validation.ToInt(Sys0a60Manager.Entity.CreateSn("ord9a00_listid", usercode));
                    model.Createdate = now;
                    model.Muser = appstr;
                    model.Seller = seller;
                    model.Shopid = shopid;
                    model.Sellid = sellid;
                    model.Sellertime = sellertime;

                    lst.Add(Ord9a00Manager.Entity.Add(model));
                }
            }

            return CommonManager.Entity.SaveData(lst);
        }

        public string SaveEditData(Hashtable tb, string action, string usercode)
        {
            List<SqlApp> lst = new List<SqlApp>();

            Ord9a00 model = null;
            if ("M" == action)
            {
                int listid = Validation.ToInt(tb["listid"]);
                model = this.GetModelById(listid);
                if (null == model) return "该笔销售单可能已经被删除，请重新操作！";

                Components.CommonUtil.GetInstance.CopyProperties(tb, model);
              
                //执行新增
                lst.Add(this.Update(model));
            }

            return CommonManager.Entity.SaveData(lst);
        }

        #endregion
    }
}



